--
-- Created by IntelliJ IDEA.
-- User: 13911
-- Date: 2019/7/1
-- Time: 18:18
-- To change this template use File | Settings | File Templates.
--

local socket = require("socket.core") /*require socket module*/
local tcp = socket.tcp()
local host = host or '127.0.0.1'
local port = '8800'
local tcpbind = tcp:bind(host,port)
if(tcpbind and tcpbind == 1) then
    print('Binding to host'..host)
else
    print('Binding error')
end
local e = tcp:listen(50)
if(e and e == 1) then
    print('listen ok')
else
    print('listen error')
end
print('waiting connect cli')
while 1 do
    local client = tcp:accept()
    if(client ~= nil) then
        print('access success')
    else
        print('accept err')
    end
    /*等待有至少10字节*/
    local revbuff = client:receive(10)
    print('revbuff:'..revbuff)
    if(revbuff == 'hello 1111') then
        local sendcli = client:send('hello lua cli')
        if(sendcli) then
            print('sendcli ok')
        else
            print('sendcli error')
        end
    else
        print('rec error , not send msg')
    end

end
  tcp:close()



